const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curIndex: 0,
    curpage: 1,
    hasmore: true,
    share_detail_list: [],
    type: 3
  },
  onLoad: function (options) {
    var self = this;
    wx.getStorage({
      key: 'key',
      success: res => {
        self.data.key = res.data;
        self.getRewardInfo();
      }
    })
  },
  getRewardInfo: function (type = 3) {
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=commander_reward_detail',
      data: {
        key: self.data.key,
        share_handle: type,
        curpage: self.data.curpage
      },
      method: 'GET',
      success: function (res) {
        console.log(res.data)
        if (res.data.code == 200) {
          self.setData({
            share_detail_list: self.data.share_detail_list.concat(res.data.datas.share_detail_list),
            hasmore: res.data.hasmore
          })
        }
        if (res.data.hasmore) {
          self.data.curpage++;
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  changeIndex: function (e) {
    wx.pageScrollTo({
      scrollTop: 0
    })
    this.setData({
      curIndex: e.currentTarget.dataset.index
    })
    let index = e.currentTarget.dataset.index;
    if (index == 0) {
      this.data.type = 3
    } else if (index == 1) {
      this.data.type = 1
    } else if (index == 2) {
      this.data.type = 2
    }
    this.data.curpage = 1;
    this.data.hasmore = true;
    this.data.share_detail_list = [];
    this.getRewardInfo(this.data.type);
  },
  onReachBottom: function () {
    if (this.data.hasmore) {
      this.getRewardInfo(this.data.type);
    }
  },
})